package ru.urfc.portal.ui.client.renderers;

import ru.urfc.portal.ui.client.descriptor.GridField;
import ru.urfc.portal.ui.client.widgets.MegaGrid;

import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;

public abstract class BaseRenderer implements GridCellRenderer<ModelData> {
	protected GridField field;
	
	public BaseRenderer(GridField field) {
		super();
		this.field = field;
	}

	@Override
	public Object render(ModelData modelData, String property, ColumnData config,
			int rowIndex, int colIndex, ListStore<ModelData> store,	Grid<ModelData> grid) {
		if (grid instanceof MegaGrid) {
			init((MegaGrid) grid);
		}
		return renderCell(modelData);
	}
	
	protected abstract void init(MegaGrid grid);

	public abstract void renderElements(ModelData modelData);

	public abstract Object renderCell(ModelData modelData);
	
	public GridField getField() {
		return field;
	}

	public abstract void updateModel(ModelData modelData);
	
}
